package com.atguigu.tingshu.user.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/***
 * 账户初始化使用rabbit配置
 */
@Configuration
public class UserAccountInitRabbitConfig {


    /**
     * 初始化用户账户消息交换机
     * @return
     */
    @Bean("accountInitExchange")
    public Exchange accountInitExchange(){
        return ExchangeBuilder.directExchange("account_init_exchange").build();
    }


    /**
     * 初始化用户账户消息队列
     * @return
     */
    @Bean("accountInitQueue")
    public Queue userAccountInitQueue(){
        return QueueBuilder.durable("account_init_queue").build();
    }

    @Bean
    public Binding userAccountInitQueueBinding(@Qualifier("accountInitExchange") Exchange accountInitExchange,
                                               @Qualifier("accountInitQueue") Queue accountInitQueue){
        return BindingBuilder
                .bind(accountInitQueue)
                .to(accountInitExchange)
                .with("account.init")
                .noargs();
    }


}
